class Solution {
public:
    int maxScoreSightseeingPair(vector<int>& values) {
        int ans = -1000000;
        priority_queue<int> que;
        que.push(values.back() - values.size() + 1);
        for (int i = values.size() - 2; i >= 0; i--)
        {
            ans = max(ans, values[i] + i + que.top());
            que.push(values[i] - i);
        }
        return ans;
    }
};